package com.learning.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.learning.model.Users;
import com.learning.service.LoginService;

@Controller
public class LoginController {

	@Autowired
	private LoginService loginService;
	
	@RequestMapping(value="/login")
	public ModelAndView checkLogin(HttpServletResponse response, HttpServletRequest request,
			@RequestParam(value = "username", required = false) String userName , 
			@RequestParam(value = "password", required = false) String password ) {
		ModelAndView view = null;
		Users user = new Users(userName, password);
		if( loginService.CheckLogin(user)) {
			view = new ModelAndView("success");
		} else {
			view = new ModelAndView("login");
		}
			
		return view;
	}
}
